export default class CusCodeQuick extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            TempCom: null,
            QuickCom: null
        }
    }
    componentDidMount() {
        this.update(this.props)
    }
    componentWillReceiveProps(nextProps) {
        if(this.props.templateKey !== nextProps.templateKey){
            this.update(nextProps);
        }
    }
    update = (props) => {
        if (props.templateKey) {
            import(`./template/${props.templateKey}`).then(d => {
                this.setState({
                    TempCom: d.default
                })
            }).catch(() => {
                this.setState({
                    TempCom: null
                })
            })
            import(`./quick/${props.templateKey}`).then(d => {
                this.setState({
                    QuickCom: d.default
                })
            }).catch(() => {
                this.setState({
                    QuickCom: null
                })
            })
        }
    }
    render() {
        const { TempCom, QuickCom } = this.state;
        return (
            <div className="edc-excel-code-qs">
                {QuickCom && <QuickCom ecId={`${this && this.props && this.props.ecId || ''}_QuickCom@syb9pq`} insertScript={this.props.insertScript} designerStore={this.props.designerStore}/>}
                {TempCom && <TempCom ecId={`${this && this.props && this.props.ecId || ''}_TempCom@nlljrl`} />}
            </div>
        )
    }
}